<template>
	<view>
		<view class="lb-main-32">
			<u-empty v-if="listData.length < 1" mode="coupon" icon="/static/empty/coupon.png"></u-empty>
			<view class="lb-box" v-for="(item,index) in listData" :key="index">
				<image src="/static/bg-imgs/coupon-bg.png" mode=""></image>
				<view class="box-item">
					<view class="box-left">
						<view class="price">
							<text>¥</text>
							{{item.discount_amount*1}}
							<text>元</text>
						</view>
						<view class="tip" v-if="item.type==2">
							{{item.max_condition > 0 ? `满${item.max_condition}可用`:''}}
						</view>
					</view>
					<view class="box-centre">
						<view class="title">
							{{item.title}}
						</view>
						<view class="tip">
							{{item.expire_time ? item.expire_time + '前有效':''}}
						</view>
					</view>
					<view class="box-right" @click="neck(item)">
						领取
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCouponApiList,
		neckCouponApi
	} from "@/api/apis/wash.js"
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				listData: [],
				isLoading: false,
				pageType: 0
			}
		},
		onReachBottom() {
			//注意 这里是重要的一步，不满足条件下拉加载不能继续请求数据
			if (!this.isLoading) {
				this.getList();
			}

		},
		methods: {
			//列表
			getList() {
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				this.isLoading = true;
				getCouponApiList({
					// is_recommend: 1,
					type: this.pageType,
					page: this.page,
					limit: this.limit,
				}).then(res => {
					uni.hideLoading();
					if (this.page == 1) {
						this.listData = res.data.data;
					} else {
						this.listData = this.listData.concat(res.data.data);
					}
					if (res.data.total > this.page * this.limit) {
						// console.log(res.data.length)
						//请求成功 节流阀 设置为false（没有走完函数不允许再次请求）
						this.isLoading = false;
						this.page++;
					}
				})
			},
			//领取
			neck(item) {
				uni.showLoading({
					title: "请求中",
					mask: true
				});
				this.isLoading = true;
				neckCouponApi({
					coupon_id: item.id,
				}).then(res => {
					uni.hideLoading();
					if (res.code == 1) {
						this.$u.toast('领取成功!');
						setTimeout(() => {
							this.page = 1;
							this.getList();
						}, 1500)
					}
				})
			}
		},
		onLoad(e) {
			this.pageType = e.type ? e.type : 0
			this.getList();
		}
	}
</script>

<style lang="scss">
	.lb-box {
		position: relative;
		width: 100%;
		height: 162rpx;
		display: flex;
		// justify-content: space-between;
		align-items: center;
		margin-bottom: 24rpx;

		image {
			position: absolute;
			top: 0;
			left: 0;
		}

		.box-item {
			width: 100%;
			position: relative;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.box-left {
				.price {
					font-size: $main-font-36;
					color: #F65D40;

					text {
						// content: '¥ ';
						font-size: $main-font-24;
						color: #F65D40;
					}

					// &::before {
					// 	content: '¥ ';
					// 	font-size: $main-font-24;
					// 	color: #F65D40;
					// }
				}

				.tip {
					font-size: $main-font-20;
					color: #9B9B9B;
					padding-top: 8rpx;
				}
			}

			.box-centre {
				.title {
					font-size: $main-font-28;
					font-weight: bold;
					color: #F65D40;
				}

				.tip {
					font-size: $main-font-20;
					color: #9B9B9B;
					padding-top: 8rpx;
				}
			}

			.box-right {
				width: 120rpx;
				height: 48rpx;
				background: linear-gradient(126deg, #F7583F 0%, #F28F4C 100%);
				border-radius: 24rpx;
				line-height: 46rpx;
				text-align: center;
				font-size: $main-font-24;
				color: $main-font-color-white;
			}
		}
	}
</style>